A simple lookup
Consider the following example: A Platform page includes a lookup field (see Relationships between objects) for a property and an amount for a proposed mortgage. Upon selection of the property, we want to use the property's value as the default for the mortgage amount. This means a server-side trip using the AJAX API, as illustrated below.
To implement this example, follow these steps:
- Create the objects Property and Mortgage, with a one-to-many relationship between Property and Mortgage (one property can have more than one mortgage)
- For the Property lookup field in the Mortgage object definition, implement the
following onchange event handler:
if (typeof cust_populateAmount=='function') cust_populateAmount(); - Add the following script component to the New Mortgage
page using the page editor:
<script> function cust_populateAmount() { var propId = document.theForm.R4388623.value; rbf_getFields("property1", propId, "appraisal_amount", cust_callbackAmount); } function cust_callbackAmount(objName, id, dataValues) { if (document.theForm.amount.value == '') rbf_setFieldValue('amount',dataValues.appraisal_amount); } </script>
Now, when the Property lookup field is updated, it triggers an AJAX call to Platform and assuming that the requested record exists and the user has appropriate access rights, the value of the appraisal_amount field will be set as the default to the amount field.